import React from 'react';
import ReactDOM from 'react-dom';
import { createHashHistory } from 'history';
import { Router, Route, useRouterHistory } from 'react-router';
import { syncHistoryWithStore, RouterStore } from 'mobx-react-router';
import { Provider } from 'mobx-react';
import { WeaDebugRouteMenu } from 'ecCom';
import { WeaLicense, WeaLicenseSubmit, WeaPlugin, WeaNonStandard, WeaSystemSetting, WeaVersion } from './index';

const routing = new RouterStore();
const allStore = { routing };

const browserHistory = useRouterHistory(createHashHistory)({
  queryKey: '_key',
  basename: '/',
});

const history = syncHistoryWithStore(browserHistory, routing);

window.weaHistory = history;

class Root extends React.Component {
  render() {
    return (
      <Provider {...allStore}>
        <Router history={history}>
          <Route path="/" component={WeaDebugRouteMenu}>
            <Route path="license" component={WeaLicense} />
            <Route path="licensesubmit" component={WeaLicenseSubmit} />
            <Route path="plugin" component={WeaPlugin} />
            <Route path="nonstandard" component={WeaNonStandard} />
            <Route path="systemsetting" component={WeaSystemSetting} />
            <Route path="version" component={WeaVersion} />
          </Route>
        </Router>
      </Provider>
    );
  }
}

ReactDOM.render(<Root />, document.getElementById('container'));
